<template>
	<div id="app">
		<view class="main-pop">
			<image class="laba" src="https://admin.cqycgyl.com/uploads/20250917/d48832b080e9a68c8a0c66197e915739.png"></image>
			<view class="main-tip">您好，入驻申请已经通过了，可以上传商品了</view>
			<view class="main-watch">查看</view>
		</view>
			
	</div> 
</template>
<script>
	import tools from '@/common/tools.js'
	export default {
		data(){
			return {
				socket: undefined
			}
		} ,
		globalData: {
			tools,
			system:{},
			latitude: undefined,
			longitude: undefined,
		},
		onLoad(){
		},
		onLaunch(e) {
			let sceneParams = tools.handleScene(e.query?.scene)  
			let _this = this
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				console.log(res.hasUpdate);
			});
			updateManager.onUpdateReady(function(res) {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});
			});
			// 使用 uni-push 获取自己的 cid (client id)
			// 只有在 APP-PLUS 环境下生效
			// onLaunch 里调用获取 cid，并可打印出来用于后续推送测试
			//#ifdef APP-PLUS
			uni.getPushClientId({
			success(res) {
				console.log('cid',res);
				uni.onPushMessage((res) => {
					console.log("收到推送消息：",res) //监听推送消息
					plus.push.createMessage({
						title: res.title,
						content: res.content,
						success: (res) => {
							console.log("推送消息发送成功：",res)
						}
					})
				})



			},
			fail(err) {
				console.log(err)
				this.globalData.cid = '';
			}
			})
			
			//#endif
		},
		onShow() {
			this.audioContext = uni.createInnerAudioContext();
			this.audioContext.src = 'https://admin.cqycgyl.com/uploads/20250917/9d9d577e9d9dba8a39c495cf3edc6d7c.mp3';
			console.log('App Show');
			this.connectSocket();
		},
		onHide: function() {
			console.log('App Hide')
			// uni.stopLocationUpdate();
		},
		methods: {
			connectSocket(){
				// uni.connectSocket 返回的是一个SocketTask对象，不能直接在上面绑定 onOpen/onMessage，需要用 socketTask.onOpen/onMessage 方法
				const socketTask = uni.connectSocket({
					url: 'wss://admin.cqycgyl.com/ws?user_id='+this.vuex_user.user_id,
					// 增加超时设置（可选，默认60s）
					timeout: 10000,
					// 监听连接发起是否成功（辅助排查）
					success: () => {
					console.log('WebSocket连接请求已发起',this.vuex_user.user_id);
					},
					fail: (err) => {
					console.error('WebSocket连接请求失败', err);
					this.connectSocket();
					}
				});
				this.socket = socketTask;
				socketTask.onOpen(() => {
					console.log('连接成功');
					this.$u.api.notice.getMessageList({
						uid: this.vuex_user.user_id,
						all: 0
					}).then(res => {
						this.$u.vuex('vuex_msg',res.data.map(item=>{
							return JSON.parse(item.data);
						}));
						console.log('vuex_msg',this.vuex_msg);
					})
				});
				socketTask.onMessage((event) => {
					let data = JSON.parse(event.data);
					 
					let msgData = data.message;
					this.handleMessage(msgData)
					
				});
				this.socket.onClose = () => {
					console.log('连接关闭');
					this.socket = undefined;
					this.connectSocket();
				}
				this.socket.onError = (event) => {
					console.log('连接错误',event);
					this.socket = undefined;
				}
			},
			handleMessage(data){
				console.log('收到消息',data);
				console.log('vuex_msg',this.vuex_msg)
				let vuex_msg = uni.getStorageSync('lifeData').vuex_msg||[];				
				console.log('vuex_msg',vuex_msg);
				
				if(data.modal == 1){
					
					uni.showModal({
						title: data.msg,
						icon: 'none',
						success: (res) => {
							if(res.confirm){
								uni.navigateTo({
									url: data.url
								});
							}
						}
					});
				}else{
					uni.showToast({
						title: data.msg,
						icon: 'none'
					});
				}

				vuex_msg = [data ,...vuex_msg];
				const count = vuex_msg.filter(item => item.read == false).length;
				console.log('count',count);
				wx.setTabBarBadge({
					index: 2,
					text: ''+count
				});
				this.audioContext.play();
				this.$u.vuex('vuex_msg',vuex_msg);
				
			}
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	@import "static/css/iconfont.css";
	
	body {
		background-color: #f7f7f7;
		color: #666;
	}
	
	.main-pop{
		position: fixed;
		top: 176rpx;
		left: 50rpx;
		width: 650rpx;
		height: 64rpx;
		z-index: 999;
		border-radius: 12rpx  12rpx  12rpx  12rpx;
		background-color: #FEF2DF;
		padding: 16rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.laba{
			width: 32rpx;
			height: 32px;
		}
		.main-tip{
			font-weight: 500;
			font-size: 24rpx;
			color: #F16325;
			line-height: 24rpx;
		}
		.main-watch{
			width: 90rpx;
			height: 40rpx;
			background: #F16325;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;
			line-height: 24rpx;
			margin-left: auto;
		}
	}
	
	.b {
		border: 1px solid red
	}

	.page-grad {
		z-index: -1;
		background: linear-gradient(#07c160, #eee);
		height: 400rpx;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
	}

	.box-card {
		box-shadow: 0px 2rpx 10rpx 0px rgba(0, 0, 0, 0.1);
		background-color: white;
		margin: 10rpx 26rpx 24rpx 26rpx;
		padding: 30rpx;
		border-radius: 16rpx;
	}
	
	.text-1-row{
		white-space: normal;
		word-break: break-all;
		text-overflow: ellipsis;
		display:-webkit-box;
		line-clamp:1;
		-webkit-line-clamp:1;
		-webkit-box-orient:vertical;
		overflow: hidden;
	}
	.text-2-row{
		white-space: normal;
		word-break: break-all;
		text-overflow: ellipsis;
		display:-webkit-box;
		line-clamp:2;
		-webkit-line-clamp:2;
		-webkit-box-orient:vertical;
		overflow: hidden;
	}
	
	// 弹出框样式
	.popup-cover{
		width: 100vw;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.7);
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 998;
	}
	.bottom-popup-mask {
	  position: fixed;
	  bottom: 0;
	  left: 0;
	  right: 0;
	  top: 0;
	  margin: auto;
	  border-radius: 16rpx;
	  width: 70%;
	  height: 40%; /* 可以根据需要调整高度 */
	  z-index: 999;
	}
	.bottom-popup-content {
	  padding: 20px;
	  margin: 10px;
	  border-radius: 10px;
	}
	.popup-box{height: 560rpx;width: 540rpx;position: absolute;left: 0;right: 0;bottom: 0;top: 0;margin: auto;}
	.popup-title{position: absolute;top: 230rpx;left: 0; width: 100%;text-align: center;font-size: 44rpx;font-weight: bold;color: black;z-index: 999;}
	.popup-content{position: absolute;top: 320rpx;left: 60rpx; width: 100%;text-align: center;font-size: 28rpx;z-index: 999; width: 420rpx;}
	.popop-btn-box{width: 100%;position: absolute;left: 0rpx;bottom: 50rpx;display: flex;justify-content: center;}
	.popop-btn{width: 432rpx;height: 72rpx;background-color:rgba(54, 190, 106, 1) ;color: white;border-radius: 36rpx;text-align: center; font-size: 28rpx;line-height: 72rpx;}
</style>